<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>

    function Person(name, age) {
      this.name = name;
      this.age = age;
    }

    Person.prototype.sayHello = function() {
      console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
    };

    const person1 = new Person('Alice', 30);

    // 使用 for...in 循环遍历对象的属性, 包括原型链的属性
    for (let i in person1) {
      console.log(i); // name age
    }

  </script>
</body>
</html>